package logger

import (
	"log"
	"os"
	"path/filepath"
	"time"
)

func InitLogger() {
	logDir := "logs"
	if _, err := os.Stat(logDir); os.IsNotExist(err) {
		os.Mkdir(logDir, 0755)
	}
	logFile := filepath.Join(logDir, time.Now().Format("2006-01-02")+".log")
	logOut, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err != nil {
		log.Fatal(err)
	}
	log.SetOutput(logOut)
}

func LogMessage(level, message string) {
	log.Printf("[%s] %s\n", level, message)
}
